package com.doule.farmerassistant.task;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.doule.farmerassistant.R;

import java.util.ArrayList;

/**
 * Task adapter.
 * 
 * @author riguang
 * 
 */
public class TaskAdapter extends BaseAdapter {
    /**
     * Contact data list.
     */
    private final ArrayList<TaskDetail> mData;
    
    /**
     * LayoutInflater.
     */
    private LayoutInflater inflater = null;

    /**
     * TaskAdapter constructor.
     * @param context
     * Context
     * @param data
     * TaskDetail list
     */
    public TaskAdapter(Context context, final ArrayList<TaskDetail> data) {
        mData = data;
        inflater = LayoutInflater.from(context);
    }

    /**
     * get Contact list.
     * 
     * @return mData
     */
    public final ArrayList<TaskDetail> getContactList() {
        return mData;
    }

    @Override
    public final int getCount() {
        return mData.size();
    }

    @Override
    public final Object getItem(final int position) {
        return mData.get(position);
    }

    @Override
    public final long getItemId(final int position) {
        return position;
    }

    @Override
    public View getView(final int position, final View convertView,
            final ViewGroup parent) {
        // TODO Auto-generated method stub
        View vi = convertView;
        if (vi == null) {
            vi = inflater.inflate(R.layout.task_row, null);
        }

        TextView taskName = (TextView) vi.findViewById(R.id.tv_task_name);
        String name = mData.get(position).getName();
        taskName.setText(name);

        return vi;
    }
}
